<template>
  <div>
    {{ selection }}
    <br>
    <el-select v-model="selection" placeholder="请选择数据名" clearable multiple>
      <el-option v-for="item in masterList" :key="item.id" :label="item.name" :value="item.id">
        <span>{{ item.name }}</span>
        <span style="float:center; color: #8492a6; margin-left: 10px;">{{ item.dataCategory }}</span>
        <span style="float:right; color: #8492a6; margin-left: 10px;">{{ getPlantLabelByMasterId(item.id) }}</span>
      </el-option>
    </el-select>
  </div>
</template>

<script setup name="SearchPlant" lang="ts">
import { KpiMasterVO } from '@/api/manu/kpiMaster/types';

const masterList = defineModel<KpiMasterVO[]>('masterList');
const selection = defineModel('selection');

interface plantVo {
  key: string;
  value: string;
  type: string;
}

const plantOrgList = reactive<plantVo[]>([
  { key: 'plant', value: '工厂', type: '1' },
  { key: 'bv', value: 'BV', type: '2' },
  { key: 'hm', value: 'HM', type: '2' },
]);

const getPlantLabelByMasterId = (masterId: string | number) => {
  const master = masterList.value.find(item => item.id == masterId);
  return plantOrgList.find(item => item.key == master?.scope)?.value;
}

</script>
